<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-card>
        <el-form-item label="类型 " prop="engineerType">
          <el-select v-model="queryParams.engineerType" placeholder="请选择子工程类型 " clearable size="small">
            <el-option
              v-for="(dict,index) in dict.type.sys_sub_engineer_type"
              :key="'b'+index"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入子工程名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="代码" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入子工程代码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-card>
    </el-form>

    <el-card style="margin-top:10px;">
      <el-table v-loading="loading" :data="subEngineerList" @selection-change="handleSelectionChange" border>
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column label="代码" align="center" prop="code" />
        <el-table-column label="类型" align="center" prop="engineerTypeName">
           <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_sub_engineer_type" :value="scope.row.engineerType"/>
          </template>
        </el-table-column>
        <el-table-column label="所属工程" align="center" prop="engineerName" />
        <el-table-column label="所属项目" align="center" prop="projectName" />
        <el-table-column label="启动日期" align="center" prop="startTime" />
        <el-table-column label="竣工日期" align="center" prop="endTime" />
        <el-table-column label="负责人" align="center" prop="chargerName" />
        <el-table-column label="负责部门" align="center" prop="deptName" />
        <el-table-column label="金额(万元)" align="center" prop="costConstruction">
          <template slot-scope="scope">
            <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column label="施工单位" align="center" prop="ownerDept" />
        <el-table-column label="监理单位" align="center" prop="supervisor" />
        <el-table-column label="施工联系人" align="center" prop="contactPerson" />
        <el-table-column label="联系方式" align="center" prop="contactPhone" />
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-dropdown :hide-on-click="false">
              <span class="el-dropdown-link" style="color:blue;">
                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleView(scope.row)"><i class="el-icon-document"></i>子工程详情</el-dropdown-item>
                <el-dropdown-item style="color:blue;" @click.native="handleSubEngineerDataset(scope.row)"><i class="el-icon-view"></i>数据集权限</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 详情 -->
    <el-dialog :title="vTitle" :visible.sync="vOpen" width="70%" append-to-body>
      <el-card style="margin-top:-30px">
        <div slot="header" class="clearfix">
          <center><span style="font-weight:bold;font-size:18px;">{{ subEngineerDetail.name }}</span></center>
        </div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="子工程编码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.subEngineerNo }}
          </el-descriptions-item>
          <el-descriptions-item label="子工程代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.ownerDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="子工程状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_sub_engineer_status" :value="subEngineerDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="子工程金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.costConstruction | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="类型" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_sub_engineer_type" :value="subEngineerDetail.engineerType"/>
          </el-descriptions-item>
          <el-descriptions-item label="所属工程" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.engineerName }}
          </el-descriptions-item>
          <el-descriptions-item label="所属项目" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.projectName }}
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ subEngineerDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(subEngineerDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="子工程描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ subEngineerDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ subEngineerDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </el-card>
      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">子工程图片</span>
        </div>
        <new-preview v-if="subEngineerDetail.contractAttach!=null" :src="subEngineerDetail.contractAttach" :width="200" :height="200" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">子工程附件</span>
        </div>
        <file-upload-show :fileList_show="fileList_show" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目信息</span>
        </div>
        <el-descriptions v-if="projectDetail!=null" :column="2" border>
          <el-descriptions-item label="项目名称" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.name }}
          </el-descriptions-item>
          <el-descriptions-item label="项目代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="项目状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_project_status" :value="projectDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(projectDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions v-if="projectDetail!=null" :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="项目金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.totalInvest | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="项目描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
        <span v-if="projectDetail==null" style="color:red;">暂未挂接项目</span>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程信息</span>
        </div>
        <el-descriptions v-if="engineerDetail!=null" :column="2" border>
          <el-descriptions-item label="工程名称" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.name }}
          </el-descriptions-item>
          <el-descriptions-item label="工程代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.ownerDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="工程状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_engineer_status" :value="engineerDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="工程金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.costConstruction | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="所属项目" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.projectName }}
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(engineerDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions v-if="engineerDetail!=null" :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="工程描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ engineerDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ engineerDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
        <span v-if="engineerDetail==null" style="color:red;">暂未挂接工程</span>
      </el-card>

      <el-card style="margin-top:10px" v-if="startSubEngineer==false">
            <div slot="header" class="clearfix">
                <span style="font-weight:bold;color:#1890FF;">子工程数据集</span>
            </div>
            <el-table :data="subEngineerDatasetsList" border ref="table1">
                <el-table-column type="selection" width="50" align="center" :selectable="selectable" />
                <el-table-column label="序号" align="center" type="index" />
                <el-table-column label="名称" align="center" prop="name" />
                <el-table-column label="编码" align="center" prop="code" />
                <el-table-column label="类型" align="center" prop="type" width="120">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sy_dataset_type" :value="scope.row.type"/>
                </template>
                </el-table-column>
                <el-table-column label="状态" align="center" prop="status" width="120">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==0" style="color:blue" :value="scope.row.status"/>
                    <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==1" style="color:green" :value="scope.row.status"/>
                    <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==2" style="color:red" :value="scope.row.status"/>
                </template>
                </el-table-column>
                <el-table-column label="创建人" align="center" prop="creator" width="120" />
                <el-table-column label="创建日期" align="center" prop="createTime" width="120">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                </template>
                </el-table-column>
                <el-table-column label="发布人员" align="center" prop="publisher" width="120" />
                <el-table-column label="发布日期" align="center" prop="publishTime" width="120">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
                </template>
                </el-table-column>
            </el-table>
        </el-card>

      <el-card style="margin-top:10px;" v-if="startSubEngineer==true">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">子工程数据集</span>
        </div>
        <el-table :data="subEngineerDatasetsList" border @selection-change="handleSelectionChange" :row-key="getRowKeys" ref="table">
            <el-table-column type="selection" width="50" align="center" :selectable="selectable" />
            <el-table-column label="序号" align="center" type="index" />
            <el-table-column label="名称" align="center" prop="name" />
            <el-table-column label="编码" align="center" prop="code" />
            <el-table-column label="类型" align="center" prop="type" width="120">
            <template slot-scope="scope">
                <dict-tag :options="dict.type.sy_dataset_type" :value="scope.row.type"/>
            </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status" width="120">
            <template slot-scope="scope">
                <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==0" style="color:blue" :value="scope.row.status"/>
                <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==1" style="color:green" :value="scope.row.status"/>
                <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==2" style="color:red" :value="scope.row.status"/>
            </template>
            </el-table-column>
            <el-table-column label="创建人" align="center" prop="creator" width="120" />
            <el-table-column label="创建日期" align="center" prop="createTime" width="120">
            <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
            </template>
            </el-table-column>
            <el-table-column label="发布人员" align="center" prop="publisher" width="120" />
            <el-table-column label="发布日期" align="center" prop="publishTime" width="120">
            <template slot-scope="scope">
                <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
            </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="160">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.hasProject==1" type="text" @click="unhookSubEngineerDataset(scope.row)">解除权限</el-button>
                </template>
            </el-table-column>
        </el-table>
      </el-card>

      <div slot="footer" class="dialog-footer" v-if="startSubEngineer==true">
        <el-button type="primary" @click="processSubEngineerDatasets(subEngineerDetail)">保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSubEngineer,getSubEngineer } from "@/api/system/subengineer";
import { getProject } from "@/api/system/project";
import { getEngineer } from "@/api/system/engineer";
import { getBindSubEngineerDatasets,getSubEngineerDatasets,processSubEngineerDatasets,unhookSubEngineerDataset } from "@/api/system/dataset";

export default {
  name: "SubEngineerAuth",
  dicts: ['sys_sub_engineer_status','sys_sub_engineer_type','sy_dataset_status','sy_dataset_type','sys_project_status','sys_engineer_status'],
  data() {
    return {
      engineerDetail: {},
      attachPdfName: '上传PDF',
      attachOtherName: '上传文件',
      imageName: '上传图片',
      participants: [],
      deptOptions: [],
      fileList_show:[],
      engineerList: [],
      projectDetail: {},
      moneyFormat: 4,
      subEngineerDetail: {},
      startSubEngineer: false,
      subEngineerDatasetsList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 子工程信息表表格数据
      subEngineerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      vOpen: false,
      // 弹出层标题
      vTitle: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        engineerType: null,
        name: null,
        code: null,
        startTime: null,
        endTime: null,
        costConstruction: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        EngineerNo: [
          { required: true, message: "子工程编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    unhookSubEngineerDataset(row){
        let data = {
            subEngineerIds: this.subEngineerDetail.uuid,
            uuid: row.uuid
        };
        unhookSubEngineerDataset(data).then(res =>{
            if(res.code===200){
                let query = {
                    subEngineerIds: this.subEngineerDetail.uuid
                }
                getSubEngineerDatasets(query).then(res =>{
                    this.subEngineerDatasetsList = [];
                    this.subEngineerDatasetsList = res.data;
                    var that = this;
                    that.$nextTick(() => {
                    this.subEngineerDatasetsList.forEach((v, i) => {
                        if (v.hasProject == 1) {
                            this.$refs.table.toggleRowSelection(v, true);
                        }
                    });
                    });
                })
            }
        })
    },
    /** 查询子工程信息表列表 */
    getList() {
      this.loading = true;
      listSubEngineer(this.queryParams).then(response => {
        this.subEngineerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.vOpen = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getRowKeys(row) {
      return row.uuid;
    },
    selectable(row, index) {
      if (row.hasProject == 1) {
        return false; // 禁用
      } else {
        return true; //不禁用
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleView(row){
      this.fileList_show = [];
      this.subEngineerDetail = {};
      getSubEngineer(row.uuid).then(res => {
        this.subEngineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "子工程详情";
        this.fileList_show = res.data.attachList;
        this.startSubEngineer = false;
        this.projectDetail = null;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        this.engineerDetail = null;
        if(row.engineerId!=null){
          getEngineer(row.engineerId).then(res => {
            this.engineerDetail = res.data;
          });
        }
        //获取数据集
        let query = {
            subEngineerIds: row.uuid
        }
        getBindSubEngineerDatasets(query).then(res =>{
            this.subEngineerDatasetsList = [];
            this.subEngineerDatasetsList = res.data;
            var that = this;
            that.$nextTick(() => {
            this.subEngineerDatasetsList.forEach((v, i) => {
                if (v.hasProject == 1) {
                    this.$refs.table1.toggleRowSelection(v, true);
                }
            });
            });
        })
      });
    },
    handleSubEngineerDataset(row){
      this.fileList_show = [];
      this.subEngineerDetail = {};
      getSubEngineer(row.uuid).then(res => {
        this.subEngineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "子工程详情";
        this.fileList_show = res.data.attachList;
        this.startSubEngineer = true;
        this.projectDetail = null;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        this.engineerDetail = null;
        if(row.engineerId!=null){
          getEngineer(row.engineerId).then(res => {
            this.engineerDetail = res.data;
          });
        }
        //获取数据集
        let query = {
            subEngineerIds: row.uuid
        }
        getSubEngineerDatasets(query).then(res =>{
            this.subEngineerDatasetsList = [];
            this.subEngineerDatasetsList = res.data;
            var that = this;
            that.$nextTick(() => {
            this.subEngineerDatasetsList.forEach((v, i) => {
                if (v.hasProject == 1) {
                    this.$refs.table.toggleRowSelection(v, true);
                }
            });
            });
        })
      });
    },
    processSubEngineerDatasets(row){
      let data = {
        subEngineerIds: row.uuid,
        ids: this.ids.join(",")
      };
      processSubEngineerDatasets(data).then(res =>{
        if(res.code===200){
            this.$modal.msgSuccess("保存成功");
            this.vOpen = false;
            let query = {
                subEngineerIds: row.uuid
            }
            getSubEngineerDatasets(query).then(res =>{
                this.subEngineerDatasetsList = [];
                this.subEngineerDatasetsList = res.data;
                var that = this;
                that.$nextTick(() => {
                this.subEngineerDatasetsList.forEach((v, i) => {
                    if (v.hasProject == 1) {
                        this.$refs.table.toggleRowSelection(v, true);
                    }
                });
                });
            })
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
